﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

public partial class Manager_BaoMing : System.Web.UI.PageEx
{
    private string strPageCode = "B0011";
    private string strLoginResult = string.Empty;

    private int iPageCount = 0;
    private int iRecordCount = 0;
    private string strQuery = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!DalEx.DbManagerEx.CheckLoginRight(UserType, UserId, strPageCode, ref strLoginResult))
        {
            FineUI.Alert.Show(strLoginResult, FineUI.MessageBoxIcon.Warning);
            Response.Redirect("Login.aspx");
        }
        if (!Page.IsPostBack)
        {
            DataBinds();
        }
    }
    private void DataBinds()
    {
        string strKeywords = SqlHelper.String(ttboxKeywords.Text);
        if (!string.IsNullOrEmpty(strKeywords))
            strQuery = " and (BabyName like '%" + strKeywords + "%' or ParentName like '%" + strKeywords + "%' or Mobile like '%" + strKeywords + "%')";
        DataSet ds = WebBase.Comm.SelectByPage("BaoMing2", "*", strQuery, "Id", "Id", 0, 1, gridList.PageSize, gridList.PageIndex + 1, out iPageCount, out iRecordCount);
        gridList.RecordCount = iRecordCount;
        gridList.DataSource = ds;
        gridList.DataBind();
    }

    protected void ttboxKeywords_Trigger1Click(object sender, EventArgs e)
    {
        ttboxKeywords.Text = string.Empty;
    }
    protected void ttboxKeywords_Trigger2Click(object sender, EventArgs e)
    {
        //strQuery = string.Empty;
        //string strKeywords = SqlHelper.String(ttboxKeywords.Text.Trim());
        //if (!string.IsNullOrEmpty(strKeywords))
        //    strQuery += " and (BabyName like '%" + strKeywords + "%' or ParentName like '%" + strKeywords + "%' or Mobile like '%" + strKeywords + "%')";

        DataBinds();
    }
    protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
    {
        int iPageSize = 20;
        int.TryParse(ddlPageSize.SelectedValue, out iPageSize);
        gridList.PageSize = iPageSize;
        DataBinds();
    }
    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        DataBinds();
    }
    protected void gridList_PageIndexChange(object sender, FineUI.GridPageEventArgs e)
    {
        gridList.PageIndex = e.NewPageIndex;
        DataBinds();
    }
    protected void gridList_RowCommand(object sender, FineUI.GridCommandEventArgs e)
    {
        int iSelectId = 0;
        Dictionary<int, Dictionary<int, string>> modifiedDict = gridList.GetModifiedDict();
        string strCommand = e.CommandName;
        int iResult = 0;
        string strResult = string.Empty;
        if (!string.IsNullOrEmpty(strCommand))
        {
            int iSelectIndexId = e.RowIndex;
            string strSelectId = gridList.Rows[iSelectIndexId].DataKeys[0].ToString();
            Int32.TryParse(strSelectId, out iSelectId);

            switch (strCommand)
            {
                case "Delete":
                    iResult = DalEx.BaoMing2Ex.Delete(" and Id=" + iSelectId, ref strResult);
                    break;
                case "Edit":

                    break;
            }
            if (iResult > 0)
            {
                FineUI.Alert.Show(strResult, FineUI.MessageBoxIcon.Information);
                DataBinds();
            }
            else
            {
                FineUI.Alert.Show(strResult, FineUI.MessageBoxIcon.Warning);
            }
        }
    }
    protected void btnSelectDelete_Click(object sender, EventArgs e)
    {
        string strResult = string.Empty;
        List<int> lstSelectRowId = WebBase.Comm.GetGridSeleteRowId(gridList);
        foreach (int iSelectId in lstSelectRowId)
        {
            DalEx.BaoMing2Ex.Delete(" and Id=" + iSelectId, ref strResult);
        }
        FineUI.Alert.Show(strResult, FineUI.MessageBoxIcon.Information);
        DataBinds();
    }
    protected void btnViewSign_Click(object sender, EventArgs e)
    {
        int iSelectId = 0;
        List<int> lstSelectRowId = WebBase.Comm.GetGridSeleteRowId(gridList);
        if (lstSelectRowId.Count > 0)
        {
            if (lstSelectRowId.Count > 1)
            {
                FineUI.Alert.Show("您只能选择一条报名信息进行查看！", FineUI.MessageBoxIcon.Warning);
            }
            else
            {
                winViews.IFrameUrl = "ViewSignTable2.aspx?Id=" + lstSelectRowId[0];
                winViews.Hidden = false;
            }
        }
        else
        {
            FineUI.Alert.Show("请选择要操作的订单！", FineUI.MessageBoxIcon.Warning);
        }
    }
    protected void btnCheckSave_Click(object sender, EventArgs e)
    {
        int iStatus = 0;
        string strCheckInfos = SqlHelper.String(txtCheckInfo.Text);
        int.TryParse(ddlStatus.SelectedValue, out iStatus);
        int iSelectId = 0;
        int.TryParse(hfSelectId.Text, out iSelectId);
        if (DalEx.BaoMing2Ex.UpdateStatus(iSelectId, iStatus, strCheckInfos))
        {
            FineUI.Alert.Show("报名表处理成功！", FineUI.MessageBoxIcon.Information);
        }
        else
        {
            FineUI.Alert.Show("报名表处理失败！", FineUI.MessageBoxIcon.Warning);
        }
    }
    protected void btnCheck_Click(object sender, EventArgs e)
    {
        int iSelectId = 0;
        List<int> lstSelectRowId = WebBase.Comm.GetGridSeleteRowId(gridList);
        if (lstSelectRowId.Count > 0)
        {
            if (lstSelectRowId.Count > 1)
            {
                FineUI.Alert.Show("您只能选择一条报名信息进行操作！", FineUI.MessageBoxIcon.Warning);
            }
            else
            {
                ArrayList lstStatus = new ArrayList();
                lstStatus.Add(new ListItem("未处理", "0"));
                lstStatus.Add(new ListItem("已查看", "1"));
                lstStatus.Add(new ListItem("已录取", "2"));
                lstStatus.Add(new ListItem("未录取", "3"));
                ddlStatus.DataSource = lstStatus;
                ddlStatus.DataTextField = "Text";
                ddlStatus.DataValueField = "Value";
                ddlStatus.DataBind();
                //
                iSelectId = lstSelectRowId[0];
                Model.BaoMing2 baoMing = DalEx.BaoMing2Ex.Select(iSelectId);
                if (baoMing != null)
                {
                    ddlStatus.SelectedValue = baoMing.Status.ToString();
                    txtCheckInfo.Text = baoMing.CheckInfos;
                    hfSelectId.Text = iSelectId.ToString();
                }
                winOrderCheck.Hidden = false;
            }
        }
        else
        {
            FineUI.Alert.Show("请选择要操作的订单！", FineUI.MessageBoxIcon.Warning);
        }
    }
    #region 属性转化
    protected string GetSex(object objValue)
    {
        int iValue = Convert.ToInt32(objValue);
        return iValue == 1 ? "男" : "女";
    }
    protected string GetStatus(object objValue)
    {
        string strResult = string.Empty;
        int iValue = Convert.ToInt32(objValue);
        switch (iValue)
        {
            case 0:
                strResult = "未处理";
                break;
            case 1:
                strResult = "已查看";
                break;
            case 2:
                strResult = "已录取";
                break;
            case 3:
                strResult = "未录取";
                break;
        }
        return strResult;
    }
    protected string GetClassType(object objValue)
    {
        string strResult = string.Empty;
        int iValue = Convert.ToInt32(objValue);
        switch (iValue)
        {
            case 0:
                strResult = "小班";
                break;
            case 1:
                strResult = "中班";
                break;
            case 2:
                strResult = "大班";
                break;
            case 3:
                strResult = "大大班";
                break;
        }
        return strResult;
    }
    protected string GetCensusClass(object objValue)
    {
        string strResult = string.Empty;
        int iValue = Convert.ToInt32(objValue);
        switch (iValue)
        { 
            //case 0:
            //    strResult = "龙岗";
            //    break;
            case 1:
                strResult = "深户";
                break;
            case 2:
                strResult = "非深户";
                break;
            case 3:
                strResult = "港籍";
                break;
            case 4:
                strResult = "台籍";
                break;
            case 5:
                strResult = "澳籍";
                break;
            //case 6:
            //    strResult = "外籍";
            //    break;
        }
        return strResult;
    }
    #endregion
}
